package com.bf.electroplating.controller.front;

import com.bf.electroplating.pojo.vo.ResultVO;
import com.bf.electroplating.pojo.vo.WorkshopTankDataVO;
import com.bf.electroplating.service.ElectroplatingTankService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 前端镀槽信息控制器
 * 为前端提供镀槽相关的数据接口
 *
 * @author system
 * @since 2025-01-11
 */
@Slf4j
@RestController
@RequestMapping("/api/front/electroplating-tank")
@Tag(name = "前端镀槽信息", description = "镀槽信息相关接口")
public class FrontElectroplatingTankController {

    @Autowired
    private ElectroplatingTankService electroplatingTankService;

    /**
     * 获取车间镀槽数据接口
     * 根据车间ID获取该车间下的镀槽信息，包含企业提供数据和实测数据的对比
     */
    @GetMapping("/workshop-tank-data")
    @Operation(summary = "获取车间镀槽数据", description = "根据车间ID获取该车间下的镀槽信息，包含企业提供数据和实测数据的对比")
    public ResultVO<WorkshopTankDataVO> getWorkshopTankData(
            @Parameter(description = "车间ID", required = true)
            @RequestParam("workshopId") Long workshopId) {
        try {
            log.info("获取车间镀槽数据，车间ID: {}", workshopId);
            if (workshopId == null) {
                return ResultVO.fail("车间ID不能为空");
            }
            WorkshopTankDataVO tankData = electroplatingTankService.getWorkshopTankData(workshopId);
            return ResultVO.ok(tankData);
        } catch (Exception e) {
            log.error("获取车间镀槽数据失败，车间ID: {}", workshopId, e);
            return ResultVO.fail("获取车间镀槽数据失败: " + e.getMessage());
        }
    }
}
